package com.ycMc.service.impl;

import com.ycMc.domain.InStock;
import com.ycMc.domain.Product;
import com.ycMc.mapper.InStockMapper;
import com.ycMc.mapper.ProductMapper;
import com.ycMc.service.BaseService;
import com.ycMc.service.MoneyRecordService;
import com.ycMc.service.ProductService;
import com.ycMc.utils.BaseUtils;
import com.ycMc.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by libo2 on 2017/8/23.
 */
@Service
public class ProductServiceImpl  extends BaseService implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private InStockMapper inStockMapper;

    @Override
    public void delete(String productId) {
        productMapper.delete(productId);
    }

    @Override
    public void insert(Product product) {
        product.setCreateTime(System.currentTimeMillis());
        product.setProductId(BaseUtils.generateProductId());
        product.setId(0);
    productMapper.insert(product);
    }

    @Override
    public void update(Product product) {
        productMapper.update(product);
    }

    @Override
    public List<Product> selectAll(int currentPage, int pageSize,int containZero) {

        return productMapper.select(null,null,null,null,0,0,0,0,0,containZero);
    }

    @Override
    public List<Product> select(Product product, int currentPage, int pageSize) {
     return         productMapper.select(product.getProductId(),product.getProductBrand(),product.getProductName(),product.getProductVersion(),product.getSinglePrice(),product.getStore(),product.getTradeCnt(),0,0,0);
    }

    @Override
    public Product selectOne(String productId) {
        return productMapper.selectOne(productId);
    }

    @Override
    public List<Product> query(String keyword, int currentPage, int pageSize,int containZero) {
        if(containZero==1){
            return productMapper.query(keyword,0,0,1);
        }
        else if(containZero==2)
        {
            return productMapper.query(keyword,0,0,2);
        }
        else{
            throw  new RuntimeException("新增参数containZero 1 或 2");
        }

    }

    @Override
    public void aaaaa() {

        List<Product> productList =  productMapper.select(null, null, null, null, 0, 0, 0, 0, 0,0);

        for(Product product:productList){
            InStock inStock  = new InStock();

            inStock.setAddNumber(product.getStore());
            inStock.setCreateTime(System.currentTimeMillis());
            inStock.setId(0);
            inStock.setOriginalNumber(0);
            inStock.setPresentNumber(product.getStore());
            inStock.setProductBrand(product.getProductBrand());
            inStock.setProductId(product.getProductId());
            inStock.setProductName(product.getProductName());
            inStock.setProductVersion(product.getProductVersion());
            inStock.setSupplier("系统自建");

            inStockMapper.insert(inStock);
        }
    }
}
